class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        if (nums.size() == 1)
            return 0;
        int sum = 0, suml = 0;
        for (int i = 0;i < nums.size();i++) {
            sum = sum + nums[i];
        }
        for (int i = 0;i < nums.size();i++) {
            if (suml == sum - nums[i]) {
                return i;
            }
            suml = suml + nums[i];
            sum = sum - nums[i];
        }
        return -1;
    }
};

